﻿// Copyright © Microsoft Corporation.  All Rights Reserved.
// This code released under the terms of the 
// Microsoft Public License (MS-PL, http://opensource.org/licenses/ms-pl.html.)

using System;
using System.Windows;
using Microsoft.WindowsAPICodePack.Shell;

namespace WpfGlassDemo
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Window1 : GlassWindow
    {
        public Window1()
        {
            InitializeComponent();
        }

        private void GlassWindow_Loaded(object sender, RoutedEventArgs e)
        {
            // update GlassRegion on window size change
            SizeChanged += new SizeChangedEventHandler(Window1_SizeChanged);

            // update background color on change of desktop composition mode
            AeroGlassCompositionChanged += new EventHandler<AeroGlassCompositionChangedEventArgs>(Window1_AeroGlassCompositionChanged);

            // Set the window background color
            if (AeroGlassCompositionEnabled)
            {
                // exclude the GDI rendered controls from the initial GlassRegion
                ExcludeElementFromAeroGlass(eb1);
                SetAeroGlassTransparency();
            }
            else
            {
                this.Background = System.Windows.Media.Brushes.Teal;
            }

            // initialize the explorer browser control
            eb1.NavigationTarget = (ShellObject)KnownFolders.Computer;

            // set the state of the Desktop Composition check box.
            EnableCompositionCheck.IsChecked = AeroGlassCompositionEnabled;
        }

        void Window1_AeroGlassCompositionChanged(object sender, AeroGlassCompositionChangedEventArgs e)
        {
            // When the desktop composition mode changes the background color  and window exclusion must be changed appropriately.
            if (e.GlassAvailable)
            {
                this.EnableCompositionCheck.IsChecked = true;
                SetAeroGlassTransparency();
                ExcludeElementFromAeroGlass(eb1);
                InvalidateVisual();
            }
            else
            {
                this.EnableCompositionCheck.IsChecked = false;
                this.Background = System.Windows.Media.Brushes.Teal;
            }
        }

        void Window1_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            ExcludeElementFromAeroGlass(eb1);
        }

        private void CheckBox_Click(object sender, RoutedEventArgs e)
        {
            // Toggles the desktop composition mode.
            AeroGlassCompositionEnabled = EnableCompositionCheck.IsChecked.Value;
        }

    }
}
